package com.hongxun.modules.api.controller;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.entity.DPointEntity;
import com.hongxun.modules.bss.service.DPointService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.api.entity.BOtherQuantitiesEntity;
import com.hongxun.modules.api.service.BOtherQuantitiesService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 其他工程量表
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-07-27 14:45:16
 */
@RestController
@RequestMapping("/api/botherquantities")
public class BOtherQuantitiesController {
	@Autowired
	private BOtherQuantitiesService bOtherQuantitiesService;
	@Autowired
	private DPointService dPointService;
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if(query.get("aguid")!=null&&!query.get("aguid").toString().equals(""))
		{
			wheres+=" and  b_guid = '" + query.get("aguid").toString()+"' ";
		}
        query.put("filterSql",wheres+" ");
		List<BOtherQuantitiesEntity> bOtherQuantitiesList = bOtherQuantitiesService.queryList(query);
		int total = bOtherQuantitiesService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(bOtherQuantitiesList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	@RequestMapping("/select")
	public R select(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres =" 1=1 ";
		if(query.get("dguid")!=null&&!query.get("dguid").toString().equals(""))
		{
			DPointEntity dPointEntity =dPointService.queryObject(query.get("dguid").toString());
			wheres+=" and  o_q_point = '" + dPointEntity.getPPName()+"' ";
		}
		if(query.get("subclass")!=null&&!query.get("subclass").toString().equals(""))
		{

			wheres+=" and  o_q_subclass like '%" + query.get("subclass").toString()+"%' ";
		}
		if(query.get("names")!=null&&!query.get("names").toString().equals(""))
		{

			wheres+=" and  o_q_name like '%" + query.get("names").toString()+"%' ";
		}
		query.put("filterSql",wheres+" ");
		List<BOtherQuantitiesEntity> bOtherQuantitiesList = bOtherQuantitiesService.queryList(query);
		int total = bOtherQuantitiesService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(bOtherQuantitiesList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	public R info(@PathVariable("guid") String guid){
		BOtherQuantitiesEntity bOtherQuantities = bOtherQuantitiesService.queryObject(guid);
		
		return R.ok().put("bOtherQuantities", bOtherQuantities);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody BOtherQuantitiesEntity bOtherQuantities){
		bOtherQuantitiesService.save(bOtherQuantities);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody BOtherQuantitiesEntity bOtherQuantities){
		bOtherQuantitiesService.update(bOtherQuantities);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] guids){
		bOtherQuantitiesService.deleteBatch(guids);
		
		return R.ok();
	}
	
}
